﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Controls_Common_Pager : System.Web.UI.UserControl
{
    private string m_FirstPageUrl;
    private string m_PrevPageUrl;
    private string m_NextPageUrl;
    private string m_LastPageUrl;
    private int m_PageNum;
    private int m_CurPage;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (this.EnableViewState && this.Page.IsPostBack)
        {
            object obj1 = this.ViewState["pageNum"];
            if (obj1 != null)
            {
                int num1;
                int.TryParse(obj1.ToString(), out num1);
                this.PageNum = num1;
            }
        }
        this.InitTheLinks();
        this.lb_CurPage.Text = this.m_CurPage.ToString();
    }

    private void InitTheLinks()
    {
        string CurUrl = Request.RawUrl;
        if (!string.IsNullOrEmpty(Request.QueryString["pageindex"]))
        {
            m_CurPage = Convert.ToInt32(Request.QueryString["pageindex"]);
            if (CurUrl.IndexOf("?pageindex") > 0)
            {
                this.m_FirstPageUrl = Request.RawUrl.Substring(0, CurUrl.LastIndexOf("?")) + "?pageindex=1";
                this.m_PrevPageUrl = Request.RawUrl.Substring(0, CurUrl.LastIndexOf("?")) + "?pageindex=" + (this.m_CurPage - 1).ToString();
                this.m_NextPageUrl = Request.RawUrl.Substring(0, CurUrl.LastIndexOf("?")) + "?pageindex=" + (this.m_CurPage + 1).ToString();
                this.m_LastPageUrl = Request.RawUrl.Substring(0, CurUrl.LastIndexOf("?")) + "?pageindex=" + this.m_PageNum.ToString();   
            }
            else
            {
                this.m_FirstPageUrl = Request.RawUrl.Substring(0, CurUrl.LastIndexOf("&pageindex")) + "&pageindex=1";
                this.m_PrevPageUrl = Request.RawUrl.Substring(0, CurUrl.LastIndexOf("&pageindex")) + "&pageindex=" + (this.m_CurPage - 1).ToString();
                this.m_NextPageUrl = Request.RawUrl.Substring(0, CurUrl.LastIndexOf("&pageindex")) + "&pageindex=" + (this.m_CurPage + 1).ToString();
                this.m_LastPageUrl = Request.RawUrl.Substring(0, CurUrl.LastIndexOf("&pageindex")) + "&pageindex=" + this.m_PageNum.ToString();
            }
            this.hl_FirstPage.NavigateUrl = this.m_FirstPageUrl;
            this.hl_PrevPage.NavigateUrl = this.m_PrevPageUrl;
            this.hl_NextPage.NavigateUrl = this.m_NextPageUrl;
            this.hl_LastPage.NavigateUrl = this.m_LastPageUrl;
        }
        else
        {
            m_CurPage = 1;
            this.m_NextPageUrl = Request.RawUrl + "?pageindex=2";
            this.hl_NextPage.NavigateUrl = this.m_NextPageUrl;
            this.m_LastPageUrl = Request.RawUrl + "?pageindex=" + this.m_PageNum.ToString();
            this.hl_LastPage.NavigateUrl = this.m_LastPageUrl;
        }
       
        if ((this.m_CurPage == this.m_PageNum) || (this.m_PageNum == 0))
        {
            this.hl_LastPage.Visible = false;
            this.hl_NextPage.Visible = false;
            Sep3.Visible = false;
            WSep3.Visible = false;
            Sep2.Visible = false;
            WSep2.Visible = false;
        }
        if (this.m_CurPage == 1)
        {
            this.hl_LastPage.Visible = true;
            this.hl_NextPage.Visible = true;
            Sep3.Visible = true;
            WSep3.Visible = true;
            WSep1.Visible = false;
            Sep1.Visible = false;
            WSep2.Visible = false;
            Sep2.Visible = false;
            FirstPage.Visible = false;
            this.hl_FirstPage.Visible = false;
            this.PageUp.Visible = false;
            this.hl_PrevPage.Visible = false;
        }
    }

    public int PageNum
    {
        get
        {
            return this.m_PageNum;
        }
        set
        {
            if (value > 0)
            {
                this.m_PageNum = value;
                if (this.EnableViewState)
                {
                    this.ViewState["pageNum"] = this.m_PageNum;
                }
                this.lb_PageNum.Text = this.m_PageNum.ToString();
            }
        }
    }

    public int CurPage
    {
        get
        {
            return this.m_CurPage;
        }
    }
}